// 修改导入方式，直接使用 uni. 前缀的全局 API
export function useRouter() {
  const push = (url: string, options?: RouterOptions) => {
    const { type = 'navigateTo', params = {} } = options || {}
    const query = new URLSearchParams(params).toString()
    const fullUrl = query ? `${url}?${query}` : url

    switch (type) {
      case 'navigateTo':
        uni.navigateTo({ url: fullUrl })
        break
      case 'switchTab':
        uni.switchTab({ url: fullUrl })
        break
      case 'reLaunch':
        uni.reLaunch({ url: fullUrl })
        break
      case 'redirectTo':
        uni.redirectTo({ url: fullUrl })
        break
      default:
        uni.navigateTo({ url: fullUrl })
    }
  }

  const back = (delta = 1) => {
    uni.navigateBack({ delta })
  }

  return { push, back }
}